package com.mr.service;

import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;


/**
 * @ClassName UploadService
 * @Description: TODO
 * @Author shenyaqi
 * @Date 2020/7/22
 * @Version V1.0
 **/
@Service
public class UploadService {

    public String upload(MultipartFile file) throws IOException {
        /*校验后缀名*/

        /*校验是不是图片  内容校验*/

        /*上传文件*/
        // 2.1、生成保存目录
        File imgFolder = new File("D://mr//upload//img");
        if (!imgFolder.exists()){
            imgFolder.mkdirs();
        }
        // 2.2、保存图片
        file.transferTo(new File(imgFolder, file.getOriginalFilename()));
        String url = "http://image.b2c.com/" + file.getOriginalFilename();
        return url;
    }
}
